
package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.ReceiptBean;
import com.ukao.cashregister.bean.RecheckBean;
import com.ukao.cashregister.bean.StrikeBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.PackPackagView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class PackPackagPesenter extends BasePresenter<PackPackagView> {


    public PackPackagPesenter(PackPackagView view) {
        attachView(view);
    }



    /*工厂复检返工*/
    public void stockRework(String id  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id", id);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.stockRework(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadReworkSucceed(model.getMsg());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }




                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


    /*搜索条码*/
    public void stationScanCode(Context context, String  batchCode  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("scanCode",batchCode);/*衣物条码*/
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.storeScanCode(Constant.createParameter(mHashMap)),
                new ApiCallback<RecheckBean>() {
                    @Override
                    public void onSuccess(RecheckBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadSearchData(model.getData());

                        }else{
                            mvpView.loadReworkFail(model.getMsg());

                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }
    /**
     * 衣物合格证
     */
    public void conformity(Context context, String  orderProId  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderProId",orderProId);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.conformity(Constant.createParameter(mHashMap)),
                new ApiCallback<StrikeBean>(){


                    @Override
                    public void onSuccess(StrikeBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadStrikeSucceed(model.getData());

                        }else{
                            mvpView.loadReworkFail(model.getMsg());

                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }





    /**
     打印小票
     */
    public void printReceipt(Context context, String  orderId   ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",orderId);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.printReceipt(Constant.createParameter(mHashMap)),
                new ApiCallback<ReceiptBean>(){


                    @Override
                    public void onSuccess(ReceiptBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadReceipt(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }


}
